home *** CD-ROM | disk | FTP | other *** search
- Path: bloom-beacon.mit.edu!hookup!usc!howland.reston.ans.net!europa.eng.gtefsd.com!news.umbc.edu!cs.umd.edu!kong.gsfc.nasa.gov!kong.gsfc.nasa.gov!not-for-mail
- From: dealy@kong.gsfc.nasa.gov (Brian Dealy)
- Newsgroups: comp.windows.x.motif,news.answers,comp.answers
- Subject: Motif FAQ (Part 2 of 5)
- Followup-To: poster
- Date: 14 Apr 1994 15:20:34 -0400
- Organization: NASA/Goddard Space Flight Center
- Lines: 904
- Approved: news-answers-request@MIT.Edu
- Distribution: inet
- Expires: +1 months
- Message-ID: <2ok522$5ej@kong.gsfc.nasa.gov>
- Reply-To: dealy@kong.gsfc.nasa.gov (Brian Dealy)
- NNTP-Posting-Host: kong.gsfc.nasa.gov
- Keywords: FAQ question answer
- Xref: bloom-beacon.mit.edu comp.windows.x.motif:15726 news.answers:18058 comp.answers:4909
-
-
- Archive-name: motif-faq/part2
- Last-modified: APR 04, 1994
- Version: 3.6
-
-
-
-
-
-
-
- -----------------------------------------------------------------------------
- Subject: 31) TOPIC: MOTIF GENERATORS
-
- -----------------------------------------------------------------------------
- Subject: 32) What prototyping tools are there to generate Motif code?
-
- [Last modified: June 93]
-
- Answer: [An FAQ is for "personal opinions" on these tools. I don't think it
- is appropriate to give such opinions through this particular posting, so I
- haven't included any. I will include vendor-provided descriptions provided
- they are consise and informative]
-
- `Prototyping tools' come in two forms: those that can be used to design the
- interface only (GUI builder), and those that go beyond this to give support
- for application code (User Interface Management Systems). There are a number
- of commercial and non-commercial tools of both kinds that will support the
- Motif interface. They include:
-
- GUI builders:
-
- Builder Xcessory
- iXBUILD (formerly X Build)
- ExoCODE/xm
- MOTIFATION
- X-Designer
- Druid
-
-
- UIMS:
-
- WINTERP
- ALEX
- TAE Plus
- Widget Creation Library
- UIMX
- Serpent
- TeleUse
- XFaceMaker2
- MetaCard
- ezX User Interface Management System
-
-
- Some contact addresses are:
-
-
-
- TAE Plus: Don Link, Century Computing, Inc. (301) 953-3330 tae-facts@cen.com
-
- TAE Plus is a mature, portable software development environment that supports
- rapid building, tailoring, and management of Motif-based graphical user
- interfaces. The code generator can produce C, C++ and Ada code and allows for
- merging regenerated code with previously modified parts of the interface. You
- an also generate a UIL/Mrm representation of your interface. Scripting
- capabilities are provided which facilitate automatic testing, on-line demos,
- and tutorials. A record and playback feature lets you build scripts simply by
- interacting with your GUI. A library of Dynamic Data Objects allows the user
- to create truly graphical objects whose dynamic portions can reflect data as
- well as be directly manipulated by the end-user. TAE Plus is available on
- virtually all the standard X platforms and comes with a wide array of support
- vehicles. (i.e., support office, newsletter, user's conference, etc.)
-
- WINTERP: You may obtain the current source, documentation, and examples via
- anonymous ftp from host export.lcs.mit.edu: in directory contrib/winterp you
- will find the compress(1)'d tar(1) file winterp.tar.Z. If you do not have
- Internet access you may request the source code to be mailed to you by sending
- a message to winterp-source%hplnpm@hplabs.hp.com or hplabs!hplnpm!winterp-
- source.
-
- Serpent: The S/W is free (anonymous ftp) from ftp.sei.cmu.edu. For more info
- contact erik/robert at serpent-info@sei.cmu.edu. This is no longer supported,
- and is apparently replaced by a commercial product called Alpha. TeleUSE:
- Built around X Windows and OSF/Motif, TeleUSE's comprehensive toolset gives
- you maximum control over every phase of graphical user interface development,
- including static screen layout and design, automatic implementation of
- callbacks, building the executable, and the interactive test, debug, and
- maintenance cycles.
-
- For more information, please contact:
-
- In North America and countries not specified below:
-
- Alsys (formerly TeleSoft)
- 10251 Vista Sorrento Parkway Suite 300
- San Diego, CA 92121 USA
-
- (619) 457-2700 X244
- (619) 452-1334 (fax)
- leigh@alsys.com
-
- In France: +33 1 47 66 21 83
- In the UK: +49 491 579 090
- In Scandinavia: +46 8 520 69010
- In the Benelux: +31 15 62 21 21
- In Germany: +49 7531 65022
- In Italy: +39 6 5045 1
- In Japan: +81 3 522 85620
- In South Korea: +82 2 577 2044
-
-
-
- Builder Xcessory from ICS. More details are available by sending a request to
- info@ics.com. Address: ICS Inc., 201 Broadway, Cambridge MA 02139, Tel. (617)
- 621-0060, Fax. (617) 621-9555
-
- X-Designer: From Imperial Software Technology in the UK. Email address is
- sales@ist.co.uk. (+44) 743 587055
-
- Recently, V.I. Corporation have become the distributor for the X-Designer
- product in the United States. In addition, IST and V.I. Corporation have
- developed a product called DVX-Designer that merges X-Designer with their GUI
- product called DataViews. Other merged products are in the works. For more
- information, people can contact:
-
- V.I. Corporation
- 47 Pleasant Street
- Northampton, MA 01060
- Phone: (413) 586-4144
- Fax: (413) 586-3805
- Email: vi@vicorp.com
-
- ExoCODE/xm: From Expert Object Corp., 7250 Cicero Avenue, Lincolnwood, IL
- 60646 (708)676-5555.
-
- X Build: iXOS Software GmbH, Bretonischer Ring 12,
- 8011 Grasbrunn/Munich,
- Germany,
- email support@ixos.de or office@ixos.de,
- phone ++49-89-46005 0
-
- or in the US
-
- UniPress Software,
- 2025 Lincoln Hwy.,
- Edison, NJ 08817,
- phone 1-800-222-0550
-
- ExoCode: From EXOC (Chicago, IL)
-
- UIMX: Visual Edge Software Limited, 3870 Cote Vertu, St Laurent, Quebec, H4R
- 1V4, Phone: (514) 332-6430, Fax: (514) 332-5914, or: Visual Edge Software
- Ltd., 101 First Street, Suite 443, Los Altos, CA 94022, Phone: (415) 948-0753,
- Fax: (415) 948-0843
-
- The Widget Creation Library: The distribution is available in several ways.
- The preferred approach it for you to get the compressed tar file using
- anonymous ftp from:
-
- export.lcs.mit.edu (18.30.0.238) /contrib/Wcl.1.06.tar.Z
-
-
- XFaceMaker2: NSL - Non Standard Logics S.A., 57-59, rue Lhomond, 75005 Paris
- - France, Phone: +33 (1) 43.36.77.50, Fax: +33 (1) 43.36.59.78 email:
- requests@nsl.fr or requests%nsl.fr@inria.fr for information.
-
- Their North American office: Non Standard Logics, Inc., 4141 State Street,
- Suite B-11, Santa Barbara CA 93110, Tel: 805 964 9599, Fax: 805 964 4367
-
-
- MOTIFATION: PEM GmbH, Vaihinger Strasse 49, 7000 Stuttgart 80, Germany, Tel:
- +49 (0) 711 713045, Fax: +49 (0) 711 713047 Email: basien@pem-stuttgart.de.
- Available for (Motif 1.2/1.1) on SunOS, Solaris 2.1, HP, Interactive, ODT 3.0,
- Silicon Graphics, PCS, ...
-
-
- ALEX: For more information contact Michael Karliner on (+44) 81 566 2307 or
- E-mail to alex@s-strat.co.uk. ALEX Technologies, Waterman's Yard, 32a The
- Mall, Ealing, London W5, UK.
-
- MetaCard: MetaCard 1.0 is supported on five popular UNIX/X11 platforms: SPARC,
- Sun3, DECstation, HP-9000/300, and SCO ODT. An HP-9000/700 port is underway
- and should be available by the end of July. [They] plan to support IBM
- RS/6000, SGI Iris, and DG AViiON sometime fall '92. For more information, or
- to receive a free save-disabled but licensable copy of MetaCard, email to
- info@metacard.com or call 303- 447-3936. If you have anonymous FTP access to
- the Internet, you can download the current engines, documentation, and an
- unlicensed Home stack from ftp.metacard.com (128.138.213.21), directory
- MetaCard. Commercial users can get MetaCard from world.std.com
- (192.74.137.5), directory pub/Metacard. If you don't have an anonymous ftp
- access, you can also download MetaCard from The World using kermit or xmodem
- from the ~ftp/pub/MetaCard directory. Sign up by calling 617-739-0202 (voice)
- or via modem by dialing 617-739-9753 (7 bits even parity) and logging in as
- new.
-
- MetaCard 1.2 Beta 5 is now available for anonymous FTP from ftp.metacard.com
- (directory MetaCard/1.2B5), and ftp.uu.net (directory vendor/MetaCard/1.2B5).
-
- There is also a MetaCard mailing list. To subscribe to the metacard-list,
- send mail to listserv@grot.starconn.com with the following commands in the
- body of the message:
-
- subscribe metacard-list firstname lastname
- quit
-
-
- Replace "firstname lastname" with your name, not your e-mail address.
-
-
-
- ezX User Interface Management System
- Sunrise Software, International
- 170 Enterprise Center
- Middletown, RI 02840
- 401-847-7868
- email: support@sunrise.com
-
-
-
- WKSH (Windowing Korn Shell):
-
- EXtensible Korn Shell (C language calling interface,
- dynamic library loading, etc.)
- Motif or OpenLook API
- X Toolkit Intrinsics
- WKSH Convenience Functions
- Fast Learning and Prototyping Feature (ksh interpreter)
-
-
- Contact:
- Acacia Computer,
- PO Box 4376,
- Warren, NJ 07059,
- Phone: 908 548 6955,
- Email: uunet!aca1
-
- or
-
- Computer Aid Inc, 1-(800)-444-WKSH
-
- or
-
- Consensys Corp, Europe: +(44)-734-833241 (Roger Chalke), +(44)0734-835391
- (Fax), US: (416)-940-2903, (416)-940-2903 (Fax).
-
-
- WKSH was developed by USL. Binaries are available through Acacia Computer for
- SUNOS, Solaris, SCO ODT, Intel SVR4.0
-
-
- Druid is a commercial product. It currently supports Motif1.1 and 4 unix
- platforms: SPARC, HP 9000, RS6000, and SGI.
-
- For further information contact: Mr. Fred Lee, Automated Systems (Pte)
- Limited, 203 Henderson Road, #12-07/14, Henderson Industrial Park, Singapore
- 0315. FAX: (65)272-2029
-
- Or: Dr. Gurminder Singh (gsingh@iss.nus.sg), Institute of Systems Science,
- National University of Singapore
-
-
-
-
- -----------------------------------------------------------------------------
- Subject: 33) TOPIC: TEXT WIDGET
-
- -----------------------------------------------------------------------------
- Subject: 34) What is the difference between a XmTextField widget and a single
- line XmText widget?
-
- Answer: Their functionality is the same, but the XmTextField is designed to
- give superior performance. thanks to Ken Lee, klee@synoptics.com
-
-
- -----------------------------------------------------------------------------
- Subject: 35) Why does pressing <return> in a text widget do nothing? This
- happens using Motif 1.0 when I have a text widget inside a bulletin board (or
- form) inside a dialog shell. (In Motif 1.1 it is fixed for both text and list
- widgets.)
-
- Answer: In single line mode, pressing the <return> key usually invokes the
- activate() action, and in multi-line mode, the newline() action. However,
- whenever a widget is the child of a bulletin board widget which is the child
- of a dialog shell, the bulletin board forces all of its children to translate
- <return> to the bulletin board action Return() which is usually associated
- with the default button of the dialog. To restore the text actions of
- activate() or newline(), you need to overide the Return() action of the
- bulletin board.
-
-
- /* declarations */
- /* for a single line widget */
- char newTrans[] = "<Key>Return : activate()";
- /* for a multi line widget */
- char newTrans[] = "<Key>Return : newline()";
- XtTranslations transTable;
-
- /* in executable section */
-
- transTable = XtParseTranslationTable(newTrans);
-
- /* after creating but before managing text widget */
-
- XtOverrideTranslations(textWidget, transTable);
-
-
- -----------------------------------------------------------------------------
- Subject: 36) When I add text to a scrolling text widget how can I get the new
- text to show?
-
- Answer: Use the call undocumented in Motif 1.0
-
- void XmTextShowPosition(w, position)
- Widget w;
- XmTextPosition position;
-
- where the position is the number of characters from the beginning of the
- buffer of the text to be displayed. If you don't know how many characters are
- in the buffer, use another call undocumented in Motif 1.0
-
- position = XmTextGetLastPosition(w)
-
-
- -----------------------------------------------------------------------------
- Subject: 37) Does the text widget support 16 bit character fonts?
-
-
- [Last modified: November 92]
-
- Answer: R5 has support for 16 bit character sets, and Motif 1.2 uses that.
- Neither Motif 1.0 nor 1.1 support 16 bit sets.
-
- -----------------------------------------------------------------------------
- Subject: 38) How can I stop the text widget from echoing characters typed? I
- need to turn off echo for password input.
-
- Answer: Use the modifyVerifyCallback to tell when input is received. Set the
- `doit' field in the XmTextVerifyCallbackStruct to False to stop the echo. In
- Motif 1.0 this will cause a beep per character: Live with it, because at 1.1
- you can turn it off. Note that password hiding is inherently insecure in X -
- someone may have an X grab on the keyboard and be reading all characters typed
- in anyway.
-
- Another solution often proposed is to set the foreground and background
- colours to be the same, effectively hiding the text. This has a major flaw:
- someone may select the text (triple click the mouse to get the line), and then
- paste the password into say an xterm with *different* foreground and
- background colours. This immediately shows the password.
-
- -----------------------------------------------------------------------------
- Subject: 39) How can I replace characters typed with say a `*'? I want to
- replace input for password entry.
-
- [Last modified: April 93]
-
- Answer: In Motif 1.1 Use the modifyVerifyCallback to tell when input is
- received. Set text->ptr in the callback structure to '*'. This does not work
- under 1.0 because of an oversight in which changes to this are ignored. In
- Motif 1.0, what you can do is set the doit flag to 'false' so the text is not
- displayed. Then set a static boolean to True to prevent re-entrance. Next
- call XmTextReplace() to display your '*'. then reset your re-entrance flag to
- False. XmTextReplace() will call the XmNmodifyVerify callback. To prevent
- getting into an infinite loop, you need the re-entrance flag.
-
- The following program from Dan Heller illustrates this:
-
- --------------
- /* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
- * This program is freely distributable without licensing fees and
- * is provided without guarantee or warranty expressed or implied.
- * This program is -not- in the public domain. This program appears
- * in the Motif Programming Manual, O'Reilly Volume 6.
- */
-
- /* passwd.c -- prompt for a passwd. Meaning, all input looks like
- * a series of *'s. Store the actual data typed by the user in
- * an internal variable. Don't allow paste operations. Handle
- * backspacing by deleting all text from insertion point to the
- * end of text.
- */
- #include <Xm/Text.h>
- #include <Xm/LabelG.h>
- #include <Xm/RowColumn.h>
- #include <ctype.h>
-
- void check_passwd();
- char *passwd; /* store user-typed passwd here. */
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- Widget toplevel, text_w, rowcol;
- XtAppContext app;
-
- toplevel = XtVaAppInitialize(&app, "Demos",
- NULL, 0, &argc, argv, NULL, NULL);
-
- rowcol = XtVaCreateWidget("rowcol",
- xmRowColumnWidgetClass, toplevel,
- XmNorientation, XmHORIZONTAL,
- NULL);
-
- XtVaCreateManagedWidget("Password:",
- xmLabelGadgetClass, rowcol, NULL);
- text_w = XtVaCreateManagedWidget("text_w",
- xmTextWidgetClass, rowcol, NULL);
-
- XtAddCallback(text_w, XmNmodifyVerifyCallback, check_passwd, NULL);
- XtAddCallback(text_w, XmNactivateCallback, check_passwd, NULL);
-
- XtManageChild(rowcol);
- XtRealizeWidget(toplevel);
- XtAppMainLoop(app);
- }
-
- void
- check_passwd(text_w, unused, cbs)
- Widget text_w;
- XtPointer unused;
- XmTextVerifyCallbackStruct *cbs;
- {
- char *new;
- int len;
-
- if (cbs->reason == XmCR_ACTIVATE) {
- printf("Password: %s\n", passwd);
- return;
- }
-
- if (cbs->text->ptr == NULL) { /* backspace */
- cbs->endPos = strlen(passwd); /* delete from here to end */
- if (cbs->endPos <= 0) return; /* catch null passwd - Mark Scoville */
- passwd[cbs->startPos] = 0; /* backspace--terminate */
- return;
- }
-
- if (cbs->text->length > 1) {
- cbs->doit = False; /* don't allow "paste" operations */
- return; /* make the user *type* the password! */
- }
-
- new = XtMalloc(cbs->endPos + 2); /* new char + NULL terminator */
- if (passwd) {
- strcpy(new, passwd);
- XtFree(passwd);
- } else
- new[0] = NULL;
- passwd = new;
- strncat(passwd, cbs->text->ptr, cbs->text->length);
- passwd[cbs->endPos + cbs->text->length] = 0;
-
- for (len = 0; len < cbs->text->length; len++)
- cbs->text->ptr[len] = '*';
- }
-
-
- -----------------------------------------------------------------------------
- Subject: 40) How can I best add a large piece of text to a scrolled text
- widget? In some versions of Motif 1.0 even using XmTextSetString, it insists
- on adding the text one line at a time, adjusting the scroll bar each time. It
- looks awful and is slow.
-
- Answer: If you don't have this problem, use XmTextSetString to set all of the
- text in the widget. If you do have this slowdown problem even using
- XmTextSetString, unmanage the widget, add the text and then manage it again.
- This may cause the window to blink, but you have to put up with that or switch
- to a different version of Motif.
-
- -----------------------------------------------------------------------------
- Subject: 41) How can I highlight text in the Text widget?
-
- Answer: From: argv@zipcode.com (Dan Heller)
-
- If you don't need font or color changes, you can do all this using a Text
- widget very easily [in Motif 1.1, anyway].
-
- loop() {
- pos = offset_of_pattern_in_text_widget(pattern, text_w);
- search_len = strlen(pattern);
- XmTextSetHighlight(text_w, pos, pos+search_len,
- XmHIGHLIGHT_SELECTED);
- }
-
-
- There are two choices for highlighting: reverse video (HIGHLIGHT_SELECTED) and
- underlined (HIGHLIGHT_SECONDARY_SELECTED). Be careful that your users won't
- confuse your highlights with actual selections!
-
- -----------------------------------------------------------------------------
- Subject: 42) How can I select all of the text in a widget programmatically?
- So that some initial text is displayed, but anything typed replaces it.
-
- Answer: XmTextSetSelection(Text1, 0, XmTextGetLastPosition(Text1), event-
- >xbutton.time);
-
- where Text1 is the widget in question (obviously) and event is some event that
- triggered this call. You can use XtLastTimestampProcessed( display) instead
- of xbutton.time if you don't happen to have an event pointer handy.
-
-
-
-
- -----------------------------------------------------------------------------
- Subject: 43) How can I change colours of text in the Text widget? I want
- some of the text in one colour, some in another.
-
- Answer: You can't. Text stores an ordinary string, and points where
- `highlights' of various types begin and end. These highlights are all the
- control you have over components of the text. See the previous question.
-
-
- -----------------------------------------------------------------------------
- Subject: 44) How can I change the font of text in the Text widget? I want
- some of the text in one font, some in another.
-
- Answer: You can't in Text (see the previous question). If you wanted readonly
- text, you could do it by using a label instead. Label uses XmStrings, which
- can contain multiple character sets in the one string.
-
- -----------------------------------------------------------------------------
- Subject: 45) Is there an emacs binding for the text widget?
-
- Answer: This set is due to Kee Hinckley (nazgul@alfalfa.com):
-
- *XmText.translations: #override\n\
- Ctrl <Key>b: backward-character()\n\
- Alt <Key>b: backward-word()\n\
- Meta <Key>b: backward-word()\n\
- Shift Alt <Key>b: backward-word(extend)\n\
- Shift Meta <Key>b: backward-word(extend)\n\
- Alt <Key>[: backward-paragraph()\n\
- Meta <Key>[: backward-paragraph()\n\
- Shift Alt <Key>[: backward-paragraph(extend)\n\
- Shift Meta <Key>[: backward-paragraph(extend)\n\
- Alt <Key><: beginning-of-file()\n\
- Meta <Key><: beginning-of-file()\n\
- Ctrl <Key>a: beginning-of-line()\n\
- Shift Ctrl <Key>a: beginning-of-line(extend)\n\
- Ctrl <Key>osfInsert: copy-clipboard()\n\
- Shift <Key>osfDelete: cut-clipboard()\n\
- Shift <Key>osfInsert: paste-clipboard()\n\
- Alt <Key>>: end-of-file()\n\
- Meta <Key>>: end-of-file()\n\
- Ctrl <Key>e: end-of-line()\n\
- Shift Ctrl <Key>e: end-of-line(extend)\n\
- Ctrl <Key>f: forward-character()\n\
- Alt <Key>]: forward-paragraph()\n\
- Meta <Key>]: forward-paragraph()\n\
- Shift Alt <Key>]: forward-paragraph(extend)\n\
- Shift Meta <Key>]: forward-paragraph(extend)\n\
- Ctrl Alt <Key>f: forward-word()\n\
- Ctrl Meta <Key>f: forward-word()\n\
- Ctrl <Key>d: kill-next-character()\n\
- Alt <Key>BackSpace: kill-previous-word()\n\
- Meta <Key>BackSpace: kill-previous-word()\n\
- Ctrl <Key>w: key-select() kill-selection()\n\
- Ctrl <Key>y: unkill()\n\
- Ctrl <Key>k: kill-to-end-of-line()\n\
- Alt <Key>Delete: kill-to-start-of-line()\n\
- Meta <Key>Delete: kill-to-start-of-line()\n\
- Ctrl <Key>o: newline-and-backup()\n\
- Ctrl <Key>j: newline-and-indent()\n\
- Ctrl <Key>n: next-line()\n\
- Ctrl <Key>osfLeft: page-left()\n\
- Ctrl <Key>osfRight: page-right()\n\
- Ctrl <Key>p: previous-line()\n\
- Ctrl <Key>g: process-cancel()\n\
- Ctrl <Key>l: redraw-display()\n\
- Ctrl <Key>osfDown: next-page()\n\
- Ctrl <Key>osfUp: previous-page()\n\
- Ctrl <Key>space: set-anchor()\n
-
-
- ! If you'd like the Delete key to work like backspace instead of deleting
- ! backwards, add the following definition to the lines above.
- ! <Key>osfDelete: delete-previous-character()\n\
-
- ! These aren't included because they could intefere with
- | menu accelerators (or vice versa)
- ! Alt <Key>p: backward-paragraph()\n\
- ! Meta <Key>p: backward-paragraph()\n\
- ! Shift Alt<Key>p: backward-paragraph(extend)\n\
- ! Shift Meta<Key>p: backward-paragraph(extend)\n\
- ! Alt <Key>w: copy-clipboard()\n\
- ! Meta <Key>w: copy-clipboard()\n\
- ! Ctrl Alt <Key>w: cut-clipboard()\n\
- ! Ctrl Meta <Key>w: cut-clipboard()\n\
- ! Alt <Key>y: paste-clipboard()\n\
- ! Meta <Key>y: paste-clipboard()\n\
- ! Alt <Key>f: forward-word()\n\
- ! Meta <Key>f: forward-word()\n\
- ! Alt <Key>n: forward-paragraph()\n\
- ! Meta <Key>n: forward-paragraph()\n\
- ! Shift Alt <Key>n: forward-paragraph(extend)\n\
- ! Shift Meta <Key>n: forward-paragraph(extend)\n\
- ! Shift Alt <Key>f: forward-word(extend)\n\
- ! Shift Meta <Key>f: forward-word(extend)\n\
- ! Alt <Key>d: kill-next-word()\n\
- ! Meta <Key>d: kill-next-word()\n\
- ! Alt <Key>h: select-all()\n\
- ! Meta <Key>h: select-all()\n\
-
- Similar sets of translations have been suggested by others.
-
- -----------------------------------------------------------------------------
- Subject: 46) How can I use a file as the text source for a Text widget?
-
- Answer: You can't do it directly like you can with the Athena Text widget.
- Instead, read the text from the file into a string (all of it!) and then use
- XmTextSetString. Alternatively, read blocks of characters and add them at the
- end of the text using XmTextInsertString. The following is an excerpt from
- Dan Heller's "file_browser.c":
-
- /* file_browser.c -- use a ScrolledText object to view the
- * contents of arbitrary files chosen by the user from a
- * FileSelectionDialog or from a single-line text widget.
- */
-
- ...
- struct stat statb;
-
- /* make sure the file is a regular text file and open it */
- if (stat(filename, &statb) == -1 ||
- (statb.st_mode & S_IFMT) != S_IFREG ||
- !(fp = fopen(filename, "r"))) {
- if ((statb.st_mode & S_IFMT) == S_IFREG)
- perror(filename); /* send to stderr why we can't read it */
- else
- fprintf(stderr, "%s: not a regular file0, filename);
- XtFree(filename);
- return;
- }
-
- /* put the contents of the file in the Text widget by allocating
- * enough space for the entire file, reading the file into the
- * allocated space, and using XmTextFieldSetString() to show the file.
- */
- if (!(text = XtMalloc((unsigned)(statb.st_size+1)))) {
- fprintf(stderr, "Can't alloc enough space for %s", filename);
- XtFree(filename);
- fclose(fp);
- return;
- }
-
- if (!fread(text, sizeof(char), statb.st_size+1, fp))
- fprintf(stderr, "Warning: may not have read entire file!0);
-
- text[statb.st_size] = 0; /* be sure to NULL-terminate */
-
- /* insert file contents in Text widget */
- XmTextSetString(text_w, text);
-
-
-
-
- -----------------------------------------------------------------------------
- Subject: 47) How can put Text in overstrike mode instead of insert?
-
- Answer: There is no direct way. This was posted by Edmond Pitt
- (ejp@bohra.cpg.oz) The correct answer to the question is to put the following
- in a modifyVerify callback, where 'mvcb' is the XmTextVerifyCallbackStruct,
- and 'overstriking' is defined by you:
-
- if (overstriking && mvcb->text->length == 1)
- {
- _XmTextDisableRedisplay(w,FALSE);
- XtCallActionProc(w,"delete-next-character",mvcb->event,0);
- _XmTextEnableRedisplay(w);
- }
-
- _XmText{Dis,En}ableRedisplay() are XmText{Dis,En}ableRedisplay() in 1.0, but
- X11R3 has no XtCallActionProc() anyway. For this environment you need my 1.0.3
- Text widget patches posted last year & available on request.
-
-
- -----------------------------------------------------------------------------
- Subject: 48) How can I make the Delete key do a backspace?
-
- Answer: Put this in your .Xdefaults
-
- *XmText.translations: #override <Key>osfDelete: delete-previous-character()
-
-
- -----------------------------------------------------------------------------
- Subject: 49) TOPIC: LIST WIDGET
-
- -----------------------------------------------------------------------------
- Subject: 50) Should I create an XmList widget as a child of automatic
- XmScrolledWindow or use the XmCreateScrolledList() convenience function?
-
- Answer: With most implementations, the convenience function use internal hooks
- to give somewhat better scrolling performance. thanks to Ken Lee,
- klee@synoptics.com
-
- -----------------------------------------------------------------------------
- Subject: 51) How do I best put a new set of items into a list?
-
- Answer: Set the new list count and list by XtSetArgs and install them by
- XtSetValues.
-
- XmString list[SIZE];
- int list_size;
-
- XtSetArg (args[n], XmNitemCount, list_size); n++;
- XtSetArg (args[n], XmNitems, list); n++;
- XtSetValues (w, args, n);
-
- Each time the list is reset by this the old contents are freed by the widget
- and the new supplied list is copied. Do *not* free the old list of items
- yourself as this would result in the space being freed twice. It is not
- necessary to remove the items one at a time, nor to "zero" out the list first.
-
- -----------------------------------------------------------------------------
- Subject: 52) Can I have strings with different fonts in a list?
-
- Answer: Yes. The strings are XmStrings. Each one can be created using a
- different character set using a different font.
-
-
- -----------------------------------------------------------------------------
- Subject: 53) Can I get a bitmap to show in a list item like I can in a Label?
- I want to place a bitmap along with some normal text in my list items.
-
- Answer: No. The list contains XmStrings, and these only allow text in various
- character sets. The workaround is to define your font containing the icons you
- want. Then you can create a fontlist containing your icon font and the font
- you want the text in, and then make your items multi-segment XmStrings where
- the first segment contains the code of the icon you want with a charset that
- matches the icon font in your fontlist and the second segment with a charset
- matching the text font.
-
-
- -----------------------------------------------------------------------------
- Subject: 54) Can I have items with different colours in a list?
-
- Answer: No. The list contains XmStrings, and these only allow text in various
- character sets. Since the items are XmStrings, you can already change the font
- of an item by replacing it with an item with the same text and a different
- charset tag. Adding support for color would require modification of the
- internal data structure in XmList as well as modification to the drawing
- routines. A possible workaround is to use a rowcolumn of buttons which can be
- individually set. However, you would have to do all list functionality
- yourself.
-
-
- -----------------------------------------------------------------------------
- Subject: 55) Can I grey out an item in a list? I want to make insensitive
- items in a list so that they cannot be selected.
-
- Answer:
-
- From W. Scott Meeks of OSF:
-
- Unfortunately, you can't do it directly since the list items aren't individual
- widgets. We've had other requests for this technology, but it didn't make the
- cut for 1.2; it should be in some future release.
-
- However, you can probably fake it in your application with some difficulty.
- First, a list item is an XmString, so you can specify a different charset for
- the item than for other items in the list and then specify a font in the
- list's fontlist that matches the charset and gives you the visual you want.
- The next problem is making the item unselectable. One idea would be to have
- the application keep track of the insensitive items and the items currently
- selected. Then you would set up a selection callback that when called would
- check the item selected against the list of insensitive items and if the
- selected item matched would deselect that item and reselect the previously
- selected items. Otherwise it would just update the application's list of
- selected items. The major drawback with this approach is that you'll get
- flashing whenever the list selects an item and your application immediately
- de-selects. Unfortunately I can't think of a way around this without mucking
- with the list internals.
-
- Another alternative suggested is to use instead a column of say read only text
- widgets which you can make insensitive.
-
- -----------------------------------------------------------------------------
- Subject: 56) Can I have multi-line items in a list?
- [Last modified: August 92]
-
- Answer: Motif 1.0 and 1.1 both have problems with multi-line items in a list.
- They should work okay in Motif 1.2.
-
- -----------------------------------------------------------------------------
- Subject: 57) How can I tell the position of selected items in a list?
-
- [Last modified: Oct 92]
-
- Answer: From W. Scott Meeks:
-
- 1) All XmList selection callbacks get an XmListCallbackStruct which includes
- the item selected and its position. In addition, the multiple and extended
- selection callbacks also get a list of the selected items. This approach
- requires that your application saves this information if you need it outside
- of the immediate callback.
-
- 2) At any time you can XtGetValues the XmNselectedItems and
- XmNselectedItemCount resources. The problem with this approach is that
- identical items may or may not show up in multiple times in this list and the
- position in the selectedItems list may not relate directly to the position in
- the items list.
-
- 3) You can call XmListGetSelectedPos on the list widget. This will return a
- list of the positions of all selected items.
-
- -----------------------------------------------------------------------------
- Subject: 58) TOPIC: FILE SELECTION BOX WIDGET
-
- -----------------------------------------------------------------------------
- Subject: 59) What is libPW.a and do I need it? My manual says I need to link
- in libPW.a to use the File Selection Box. I can't find it on my system.
-
- Answer: The libPW.a is the Programmers Workbench library which is an ATT
- product not included in Berkeley based systems, hence it is not found in SunOS
- or Ultrix, but is found on HP-UX (a Berkeley/ATT hybrid which chose ATT in
- this case). It contains the regex(3) routines (regcmp, regex). Some systems
- which don't have these in the libc.a need to link with -lPW. Some systems
- which have the regex(3) routines in there also have the libPW.a. If you have
- regex(3) in libc, and it works, don't link with libPW. If you don't have
- regex(3) in libc, and you don't have a libPW, then check some sites on the net
- for public domain replacements (several exist), or call your vendor.
-
- In most versions of Motif (see the doco), you can compile FileSB.c with
- -DNO_REGEX if you don't have it.
-
- -----------------------------------------------------------------------------
- Subject: 60) What are these compile errors: Undefined symbol _regcmp and
- _regex?
-
- Answer: You need to link in the libPW library - see previous question.
-
-
- -----------------------------------------------------------------------------
- Subject: 61) What's wrong with the Motif 1.0 File Selection Box? I can't set
- the directory, change the directory or get the file mask to work.
-
- Answer: The 1.0 File Selection Box is broken, and these don't work. They
- weren't fixed until Motif 1.04. Use these later versions of 1.0 or switch to
- Motif 1.1 where it changed a lot.
-
- Joe Hildebrand has a work-around for some of this: Before popping up an
- XmFileSelectionDialog, change to the directory you want. When a file is
- selected, check if it is a directory, so that we can change to it. i.e.
-
- static void show_file_box_CB(w, client_data, call_data)
- Widget w;
- Widget client_data;
- XmAnyCallbackStruct *call_data;
- {
- chdir("/users/hildjj/files");
- XtManageChild(client_data);
- }
-
- static void val_save(w, client_data, call_data)
- Widget w;
- Widget client_data;
- XmSelectionBoxCallbackStruct *call_data;
- {
- struct stat buf; /* struct stat is defined in stat.h */
- char *filename;
-
- /* get the file name from the FileSelectionBox */
- filename = SmX(call_data->value);
-
- /* get the status of the file named filename, and put it into buf */
- if (!stat(filename, &buf))
- {
- /* if it's a directory */
- /* if it's a directory */
- if(S_ISDIR(buf.st_mode))
- {
- /* change to that directory, and update the FileSelectionBox */
- chdir(filename);
- XmFileSelectionDoSearch(w, NULL);
- }
- else
- /* if it's a regular file */
- if(S_ISREG(buf.st_mode))
- /* ask if it should be overwritten */
- XtManageChild(valbox);
- else
- /* it's another kind of file. What type, i can't think of,
- but it might happen */
- pop_up_error_box(client_data, "Error saving file");
- }
- else /* we couldn't get the file status */
- {
- /* if it's because the file doesn't exist, we're golden */
- if (errno == ENOENT)
- save_file();
- else /* there is some other problem getting the status.
- e.g. bad path */
- pop_up_error_box(client_data, "Error saving file");
- }
- }
-
- this still doesn't implement the file masking stuff.
-
-
- -----------------------------------------------------------------------------
- END OF PART TWO
- --
- ..........................
-
-